//
//  VisitorView.swift
//  weibo
//
//  Created by 吴婷婷 on 15/11/4.
//  Copyright © 2015年 wutingting. All rights reserved.
//

import UIKit
import SnapKit

class VisitorView: UIView {
    
    //MARK: - 设置不同控制器视图信息
    func setupInfo(imageName:String?, title:String){
        
        messageLabel.text = title
        
        guard let imgName = imageName else{
            
            stratAnim()
            return
        }
        
        iconView.image = UIImage(named: imgName)
        homeIconView.hidden = true
        
        sendSubviewToBack(maskIconView)
        
    }
    
    private func stratAnim(){
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        
        anim.toValue = 2 * M_PI
        anim.repeatCount = MAXFLOAT
        anim.duration = 20
        
        anim.removedOnCompletion = false
        
        iconView.layer.addAnimation(anim, forKey: nil)
    }

    //MARK: - 构造函数
   override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
   required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setupUI()
    }
    
    //MARK: - 懒加载控件
    private lazy var iconView : UIImageView = UIImageView(imageName: "visitordiscover_feed_image_smallicon")
    
    private lazy var maskIconView: UIImageView = UIImageView(imageName: "visitordiscover_feed_mask_smallicon")
    
    private lazy var homeIconView : UIImageView = UIImageView(imageName: "visitordiscover_feed_image_house")
    
    private lazy var messageLabel : UILabel = UILabel(title: "关注一些人，回这里看看有什么惊喜")
    
    lazy var registerButton: UIButton = UIButton(title: "注册", backImageName: "common_button_white_disable", color: UIColor.orangeColor())

    
    lazy var loginButton: UIButton = UIButton(title: "登陆", backImageName: "common_button_white_disable", color: UIColor.darkGrayColor())
  
    
    

}

// MARK: - 设置界面
extension VisitorView {

    func setupUI(){
        
//        backgroundColor = UIColor.redColor()
        //1.添加控件
        addSubview(iconView)
        addSubview(maskIconView)
        addSubview(homeIconView)
        addSubview(messageLabel)
        addSubview(registerButton)
        addSubview(loginButton)
        
        for v in subviews{
            v.translatesAutoresizingMaskIntoConstraints = false
        }
        
        //2.设置自动布局
        //1>图标
        iconView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(self.snp_centerX)
            make.centerY.equalTo(self.snp_centerY).offset(-60)
        }
        
        // 2> 小房子
        homeIconView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(iconView.snp_center)
        }
        
        // 3> 消息文字
        messageLabel.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(iconView.snp_centerX)
            make.top.equalTo(iconView.snp_bottom).offset(16)
            make.width.equalTo(224)
            make.height.equalTo(36)
        }
        // 4> 注册按钮
        registerButton.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(messageLabel.snp_left)
            make.top.equalTo(messageLabel.snp_bottom).offset(16)
            make.width.equalTo(100)
            make.height.equalTo(36)
        }
        // 5> 登录按钮
        loginButton.snp_makeConstraints { (make) -> Void in
            make.right.equalTo(messageLabel.snp_right)
            make.top.equalTo(registerButton.snp_top)
            make.width.equalTo(registerButton.snp_width)
            make.height.equalTo(registerButton.snp_height)
        }

        
        //6>遮罩图像
//        addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-0-[mask]-0-|", options: [], metrics: nil, views: ["mask": maskIconView]))
//        
//        addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-0-[mask]-(btnHeight)-[regButton]", options: [], metrics: ["btnHeight": -36], views: ["mask": maskIconView, "regButton": registerButton]))
        // 6. 遮罩图像
        maskIconView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp_top)
            make.left.equalTo(self.snp_left)
            make.right.equalTo(self.snp_right)
            make.bottom.equalTo(registerButton.snp_bottom)
        }
        

        
        //设置背景颜色
        backgroundColor = UIColor(white: 237/255.0, alpha: 1)
        
        
        
        
    }
    
}








